import logging
import json
from functools import wraps
from .api_response import APIResponse

logger = logging.getLogger(__name__)

def handle_exceptions(func):
    """统一异常处理装饰器"""
    @wraps(func)
    def wrapper(*args, **kwargs):
        try:
            return func(*args, **kwargs)
        except json.JSONDecodeError as e:
            return APIResponse.error("数据格式错误", str(e))
        except Exception as e:
            return APIResponse.error("系统内部错误", str(e))
    return wrapper 